package poker;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Game {
    private static final String[] suits = {"♠","♥","♦","♣"};
    public List<Poker> buyPoker(){  //创造一副新牌
        List<Poker> list = new ArrayList<>();
        for (int i = 0; i < suits.length; i++) {
            for (int j = 1; j <= 13; j++) {
                Poker poker = new Poker(suits[i],j);
                list.add(poker);
            }
        }
        return list;
    }
    public void shuffle(List<Poker> list){ //随机洗牌
        for (int i = list.size()-1; i > 0; i--) {
            Random random = new Random();
            int index = random.nextInt(i);
            swap(list, i, index);
        }
    }
    private void swap(List<Poker> list, int i, int j){  //交换元素
        Poker temp = list.get(i);
        list.set(i,list.get(j));
        list.set(j,temp);
    }
    public List<List<Poker>> catchPoke(List<Poker> list){  //抓牌
        List<List<Poker>> players = new ArrayList<>(); //存放玩家的顺序表
        List<Poker> player1 = new ArrayList<>();
        List<Poker> player2 = new ArrayList<>();
        List<Poker> player3 = new ArrayList<>(); //存放玩家手牌的顺序表
        players.add(player1);
        players.add(player2);
        players.add(player3);
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Poker removePoker = list.remove(0);
                players.get(j).add(removePoker);
            }
        }
        return players;
    }

}
